package com.snail.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.snail.common.DeleteRequest;
import com.snail.model.pojo.BizPost;
import com.snail.model.vo.BizPostPageListVo;
import com.snail.response.BaseResponse;
import com.snail.response.PageResponse;
import com.snail.response.ResultUtils;
import com.snail.service.BizPostService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author Monica
 * @description
 * @date 2025/7/25 17:13
 */
@RestController
@RequestMapping("/post")
@AllArgsConstructor
public class BizPostController {

    private final BizPostService bizPostService;


    /**
     * 获取已审核的帖子分页列表(且已经订阅或者是成员)
     */
    @GetMapping("/getAuditedPostPageList")
    public PageResponse<BizPost> getAuditedPostPageList(BizPostPageListVo pageListVo) {
        return bizPostService.getAuditedPostPageList(pageListVo);
    }

    /**
     * 获取未审核的帖子分页列表
     */
    @GetMapping("/getUnauditedPostPageList")
    public PageResponse<BizPost> getUnauditedPostPageList(BizPostPageListVo pageListVo) {
        return bizPostService.getUnauditedPostPageList(pageListVo);
    }

    /**
     * 删除帖子
     */
    @PostMapping("/delete")
    public BaseResponse delete(@RequestBody DeleteRequest request) {
        return bizPostService.delete(request);
    }

    /**
     * 编辑帖子(审核)
     */
    @PostMapping("/edit")
    public BaseResponse edit(@RequestBody BizPost bizPost) {
        return bizPostService.edit(bizPost);

    }


    /**
     * 编辑帖子(发布)
     */
    @PostMapping("/publish")
    public BaseResponse publish(@RequestBody BizPost bizPost) {
        return bizPostService.publish(bizPost);
    }

    /**
     * 审核帖子
     */
    @PostMapping("/reviewPost")
    public BaseResponse<Boolean> reviewPost(@RequestParam Long teamId, @RequestParam Long id, @RequestParam Integer status) {
        Long userId = StpUtil.getLoginIdAsLong();
        Boolean reviewPost = bizPostService.reviewPost(teamId, userId, id, status);
        return ResultUtils.success(reviewPost);
    }


}
